﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Xml;
using JumbotCms.Common;

namespace JumbotCms.WebFile.Customer
{
    public partial class _activepointscard_index : JumbotCms.API.UserCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            User_Load("", "html");
            if (q("act") != "save")
            {
                Response.Write(GetPageHtml("customer_activepointscard"));
            }
            else
            {
                if (!CheckFormUrl())
                    Response.End();
                string _cardNumber = f("txtCardNumber");
                string _cardPassword = f("txtCardPassword");
                doh.Reset();
                doh.ConditionExpress = "cardnumber=@cardnumber and cardpassword=@cardpassword AND State=2";
                doh.AddConditionParameter("@cardnumber", _cardNumber);
                doh.AddConditionParameter("@cardpassword", _cardPassword);
                doh.AddFieldItem("UserId", UserId);
                doh.AddFieldItem("ActiveTime", DateTime.Now.ToString());
                doh.AddFieldItem("ActiveIP", GetUserIp());
                doh.AddFieldItem("State", 3);
                if (doh.Update("jcms_normal_pointscard") == 1)
                {
                    doh.Reset();
                    doh.ConditionExpress = "cardnumber=@cardnumber and cardpassword=@cardpassword AND State=3";
                    doh.AddConditionParameter("@cardnumber", _cardNumber);
                    doh.AddConditionParameter("@cardpassword", _cardPassword);
                    int _AddPoints = Str2Int(doh.GetValue("jcms_normal_pointscard", "Points").ToString());
                    doh.Reset();
                    doh.ConditionExpress = "id=@id AND State=1";
                    doh.AddConditionParameter("@id", UserId);
                    doh.Add("jcms_normal_user", "Points", _AddPoints);
                    string _mailBody = "ID：[" + UserId + "]，用户名[" + UserName + "]的会员于" + DateTime.Now.ToString() + "激活点卡" + _cardNumber;
                    SendServiceNotice(site.Name + "会员激活点卡", _mailBody, "1");
                    Response.Write("JumbotCms.Alert('点卡激活成功,请查看点数是否已增加', '1', \"window.location='../index/index.aspx';\");");

                }
                else
                    Response.Write("JumbotCms.Alert('点卡帐号和密码不正确', '0');");
            }
        }
    }
}
